package cn.itcast.service.impl;

import cn.itcast.mapper.DeptMapper;
import cn.itcast.pojo.Dept;
import cn.itcast.pojo.Result;
import cn.itcast.service.DeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;


@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {
    @Override
    public Result saveDept(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        boolean flag = this.save(dept);

        return flag == true ? Result.success("添加成功") : Result.error("添加失败");
    }




 /*   @Override
    public Result findAll() {
        *//*List<Dept> depts = deptMapper.selectAll();

        return Result.success("查询成功", depts);*//*
        List<Dept> depts = deptMapper.selectList(null);
        return Result.success("查询成功", depts);
    }*/

//    @Override
//    public Result deleteById(Integer id) {
//
//        /*//1.判断部门下有没有员工,如果有不能直接删除
//        //去根据部门id查询员工表,统计员工数量看是否为0
//        Integer count = empMapper.selectByDeptIdCount(id);
//        if (count == 0) {
//            deptMapper.deleteById(id);
//            return Result.success("删除成功");
//        } else {
//            return Result.error("部门下有员工,不能删除");
//        }*/
//         deptMapper.deleteById(id);
//        return Result.success("删除成功");
//    }

/*    @Override
    public Result insertByName(Dept dept) {
        *//*dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        int row = deptMapper.insertByName(dept);
        return row > 0 ? Result.success("添加成功") : Result.error("添加失败");*//*
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        int row = deptMapper.insert(dept);
        return row > 0 ? Result.success("添加成功") : Result.error("添加失败");
    }*/

/*    @Override
    public Result findById(Integer id) {
        Dept byId = deptMapper.selectById(id);
        *//*Dept byId = deptMapper.findById(id);
        return byId != null ? Result.success("查询成功", byId) : Result.error("查询失败");*//*
        return byId != null ? Result.success("查询成功", byId) : Result.error("查询失败");

    }*/

    /*@Override
    public Result updateById(Dept dept) {

        *//*dept.setUpdateTime(LocalDateTime.now());
        int row = deptMapper.updateById(dept);

        return row > 0 ? Result.success("修改成功") : Result.error("修改失败");*//*
        deptMapper.updateById(dept);
        return Result.success("修改成功");
    }*/
}
